package com.sls.game.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.ProvinceDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.ProvinceInfo;

/**
 * 
 * @Description：
 * @author wxg
 * @Date：2013-6-14
 * 
 */
@Repository("provinceDAO")
public class ProvinceDAOImpl extends SuperDAO<ProvinceInfo> implements
		ProvinceDAO {

	/**
	 * 记录插入
	 * 
	 * @param provinceInfo
	 */
	@Override
	public void insert(ProvinceInfo provinceInfo) {
		this.getSqlSession().insert("mybatis.xml.ProvinceCodeMapper.insert",
				provinceInfo);

	}

	/**
	 * 记录更新
	 * 
	 * @param provinceInfo
	 */
	@Override
	public void update(ProvinceInfo provinceInfo) {
		this.getSqlSession().update("mybatis.xml.ProvinceCodeMapper.update",
				provinceInfo);

	}

	/**
	 * 根据主键id，查询记录信息
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public ProvinceInfo queryProvinceInfoById(String id) {
		ProvinceInfo info = null;
		info = this.getSqlSession().selectOne(
				"mybatis.xml.ProvinceCodeMapper.queryProvinceInfoById", id);
		return info;
	}

	/**
	 * 分页查询
	 * 
	 * @param provinceInfo
	 * @return
	 */
	@Override
	public Pagination<ProvinceInfo> queryPagination(ProvinceInfo provinceInfo) {
		Pagination<ProvinceInfo> paginationList = null;
		int rowCount = queryRowCount(provinceInfo);
		provinceInfo.calculate();
		List<ProvinceInfo> list = queryResultList(provinceInfo);
		paginationList = queryPagination(rowCount, list, provinceInfo);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param provinceInfo
	 * @return
	 */
	private int queryRowCount(ProvinceInfo provinceInfo) {
		int rowCount = 0;
		rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.ProvinceCodeMapper.queryRowCount", provinceInfo);
		return rowCount;
	}

	/**
	 * 查询结果记录集
	 * 
	 * @param provinceInfo
	 * @return
	 */
	private List<ProvinceInfo> queryResultList(ProvinceInfo provinceInfo) {
		List<ProvinceInfo> list = null;
		list = this.getSqlSession().selectList(
				"mybatis.xml.ProvinceCodeMapper.queryResultList", provinceInfo);
		return list;
	}

	/**
	 * 根据省份名称，查询记录信息
	 * 
	 * @param id
	 * @return
	 */
	@Override
	public ProvinceInfo queryProByProvinceName(String provinceName) {
		ProvinceInfo pro = null;
		pro = this.getSqlSession().selectOne(
				"mybatis.xml.ProvinceCodeMapper.queryProByProvinceName",
				provinceName);
		return pro;
	}

	/**
	 * 根据省域编码，查询记录信息
	 * 
	 * @param provinceCode
	 * @return
	 */
	@Override
	public ProvinceInfo queryProByProvinceCode(String provinceCode) {
		ProvinceInfo pro = null;
		pro = this.getSqlSession().selectOne(
				"mybatis.xml.ProvinceCodeMapper.queryProByProvinceCode",
				provinceCode);
		return pro;
	}

}
